﻿#pragma once
#include <QGridLayout>
#include <QLabel>
#include <map>
#include <vector>
#include <string>
#include <QString>
//视频组件
#include <video_widget.h>

//宫格视频组件
class GridManager
{
 public:
  /**构造函数
   * @param gridLayout
   * @param parent
   * @param handle
  */
  explicit GridManager(QGridLayout *gridLayout,QWidget* parent,void* handle);
  
  VideoWidget* getGridForPeer(std::string peerId);

  void reset();
  void showWindow(VideoWidget* video,bool show);
  void ClosePeer(std::string peerId);

 public:
  //获取视频组件
  QGridLayout *grid(){
    return _gridLayout;
  }
  //获取父窗口
  QWidget* parent(){
      return _parent;
  }
  //获取sdk句柄
  void* handle(){
      return _handle;
  }

 private:
  //宫格
  QVector<VideoWidget *> _gridWidgets;
  //对应peer
  std::map<std::string, VideoWidget*> _peerVideos;
  QGridLayout *_gridLayout;
  QWidget* _parent{nullptr};
  void* _handle{nullptr};

 private:
    //获取一个空闲
    VideoWidget* getFirstFreeGrid() const;
    //在现有基础上添加一个视频
    void Relayout();
    void closeVideo(VideoWidget* grid);
};
